package com.woniuxy01;


import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

/**
 * @author 作者
 * @create 2025-09-10 15:24
 */


public class Test04 {
    public static void main(String[] args) throws ParseException {
        Calendar instance = Calendar.getInstance();
        //日期计算
        instance.add(Calendar.MONTH,-1);

        System.out.println(instance.get(Calendar.YEAR));
        System.out.println(instance.get(Calendar.MONTH)+1);
        System.out.println(instance.get(Calendar.DATE));
    }

    private static void test06() {
        //获取当前日历
        Calendar calendar = Calendar.getInstance();
        //设置日历
//        calendar.set(2000, 0, 12);
        calendar.set(Calendar.YEAR, 2024);

        //获取日历的某个部分的数据
        System.out.println(calendar.get(1));
        System.out.println(calendar.get(Calendar.YEAR));
        System.out.println(calendar.get(Calendar.DAY_OF_WEEK));
        System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
        System.out.println(calendar.get(Calendar.DATE));
        System.out.println(calendar.get(Calendar.DAY_OF_YEAR));
    }

    private static void test05() {
        //不是单例，是简单工厂
        Calendar calendar1 = Calendar.getInstance();
        Calendar calendar2 = Calendar.getInstance();
        System.out.println(calendar1==calendar2);
    }

    private static void test04() throws ParseException {
        Scanner sc = new Scanner(System.in);
        System.out.println("输入日期时间");
        String strDate = sc.nextLine();
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //字符串转日期
        Date date = df.parse(strDate);
        System.out.println(date);
    }

    private static void test03() {
        Date date = new Date();
        System.out.println(date);
        //构造方法指定日期格式
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //date转String
        String strDate = df.format(date);
        System.out.println(strDate);
    }

    private static void test01() {
        //创建日期对象，就代表当前日期时间
        Date date = new Date();
        System.out.println(date);
        //从1970-1-1 0点，过多少毫秒以后的时间，时差8个小时
        Date date1 = new Date(1000);
        System.out.println(date1);
        //获取当前时间
        Date date2 =new Date(System.currentTimeMillis());
        System.out.println(date2);
        System.out.println(date.getYear()+1900);
        System.out.println(date.getMonth()+1);
        System.out.println(date.getDate());
        Date date3 = new Date(2000-1900, 1-1, 1);
        System.out.println(date3);
    }
}
